/*
 * @Author: liu wang wang
 * @Date: 2020-07-15 17:48:39
 * @LastEditTime: 2020-07-21 13:14:32
 * @LastEditors: liu wang wang
 * @Description: Msg 提示框
 * @FilePath: \st-sdk-js\src\utils\Msg.ts
 */ 
import Common from './Common';
import { fadeout } from '../tools';
class Msg extends Common{
    protected timer:number= 0;
    constructor() {
        super()
    }
    public msg(text: string){
        if(this.timer){
            clearTimeout(this.timer);
        }
        const msgBox = this.createP();
        msgBox.innerText = text;
        msgBox.id = 'msg-box';
        this.setStyle(msgBox,`
        color:#fff;
        font-size:14px;
        text-align:center;
        line-height:40px;
        max-width:180px;
        background:rgba(0,0,0,0.6);
        border-radius:4px;
        padding:0 20px;
        display:inline-block;
        position:fixed;
        top:30%;
        left:50%;
        transform: translateX(-50%);
        z-index:100;
        `);
        const msgBoxEle: HTMLElement | null= document.getElementById('msg-box');
        if(msgBoxEle){
            ((msgBoxEle as HTMLElement).parentNode as HTMLElement).removeChild(msgBoxEle);
        }
        document.body.appendChild(msgBox);
        this.timer = window.setTimeout(() => {
            fadeout(msgBox);
        }, 1500);
        
    }
}

export default new Msg();